/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.erossi.pigest.web.articolo;

import org.erossi.pigest.model.articolo.Articolo;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 * 'InserisciArticoloValidator' class: effettua la validazione dei dati
 *   del form di inserimento dell'articolo. 
 *
 * @author erossi
 * @version Feb 8, 2008
 */
public class InserisciArticoloValidator implements Validator {
  
  /**
   * Verifica che sia passato l'oggetto di tipo 
   *   corretto per la validazione.
   */
  @SuppressWarnings("unchecked")
  public boolean supports(Class classe) {
    return classe.equals(Articolo.class);
  }

  /**
   * Verifica la validità dei dati in input.
   * 
   * @param command l'oggetto in cui sono stati "bindati" i dati da verificare
   * @param errors eventuali errori raccolti nel flusso
   */
  public void validate(Object command, Errors errors) {
    
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "unitaMisura", "inserisciArticolo.form.insert.items.error.units");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nome", "inserisciArticolo.form.insert.items.error.name");
    
  }
  
}

